﻿using System;
using System.Collections;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class ShowStreetOccupyEffect : LatentActionNode<int>
    {
        public BBParameter<int> currentId = 0;
        public static Action<int> OnOccupyEffectComplete;

        private bool success = false;
        public override bool allowRoutineQueueing { get { return false; } }

        private void OccupyEffectComplete(int id)
        {
            if (currentId.value == id)
            {
                success = true;
                OnOccupyEffectComplete -= OccupyEffectComplete;
            }
        }

        public override IEnumerator Invoke(int streetId)
        {
            success = false;
            OnOccupyEffectComplete += OccupyEffectComplete;
            BlueprintUtils.ShowStreetOccupyEffect(streetId);

            yield return new UnityEngine.WaitUntil(() => success);
        }
        
        public override void OnGraphStoped()
        {
            base.OnGraphStoped();
            OnOccupyEffectComplete -= OccupyEffectComplete;
        }
    }
}